package pack.actions;


import pack.projectiles.LumenMover;

import com.jme.bounding.BoundingSphere;
import com.jme.input.action.InputActionEvent;
import com.jme.input.action.KeyInputAction;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.MaterialState;
import com.jme.system.DisplaySystem;

public class FireLumen extends KeyInputAction 
{
    int numLumens;
    private Node rootNode;
    private Camera cam;
    
    public FireLumen(Node rootNode, Camera cam)
    {
    	this.rootNode = rootNode;
    	this.cam = cam;
    }

    public void performAction(InputActionEvent evt) 
    {
        Sphere bullet = new Sphere("lumen" + numLumens++, 8, 8, .25f);
        bullet.setModelBound(new BoundingSphere());
        bullet.updateModelBound();
        
        bullet.setLocalTranslation(new Vector3f(cam.getLocation()));
        MaterialState ms = DisplaySystem.getDisplaySystem().getRenderer()
        .createMaterialState();
        ms.setEmissive(new ColorRGBA(0.8f, 0.8f, 0.8f, 1));
        ms.setSpecular(ColorRGBA.white.clone());
        ms.setShininess(128);        
        
        bullet.setRenderState(ms);
        
        bullet.updateGeometricState(0, true);

        bullet.addController(new LumenMover(bullet, 
        		new Vector3f(cam.getDirection())));
        rootNode.attachChild(bullet);
        bullet.updateRenderState();
        
    }
}
